<template>
  <section>
    <order-base :orderForm="orderForm" v-on:selSku="makeOrderItems" v-on:getCustomerList="getCustomerList"></order-base>
    <order-items :orderForm="orderForm" :orderItemsForm="orderItemsForm" :customerInMemberList="customerInMemberList"></order-items>
    <order-sale :orderForm="orderForm" :orderItemsForm="orderItemsForm" v-if="orderItemsForm.length >0"></order-sale>
  </section>
</template>

<script>
  import orderSale from './orderSale'
  import orderItems from './orderItems'
  import orderBase from './newOrderBase'
  import { mapActions,mapGetters} from 'vuex'
  import DateFormat from '@/common/date-formater'
  import errHandler from '@/assets/errHandler.js'
  import Vue from 'vue'//后续添加属性，需要vue联动
  export default {
    name: "by-admin",
    components:{orderBase,orderItems,orderSale},
    data() {
      return {
        orderForm:{title:'',totalPrice:0,salePrice:0,memberId:null,departmentId:null,data:{address:{}}},
        orderItemsForm:[],
        customerInMemberList:[]
      }
    },
    watch:{
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getCustomerList(e){
        console.log('为啥没反应？？？？',e)
        this.customerInMemberList=[]
        this.customerInMemberList=this.customerInMemberList.concat(e)
      },
      makeOrderItems(e){
        console.log('看下当前的items--------',this.customerInMemberList)
        console.log('看下当选中的item--------',e)
        let index =this.orderItemsForm.findIndex(i=>i.skuId === e.skuId)
        if(index<0){
          this.orderItemsForm.push(e)
        }else {
          this.orderItemsForm[index].num +=e.num
        }
        console.log('看下之后的items--------',this.orderItemsForm)
      }
    }
  }
</script>

<style scoped>

</style>
